<?php
include_once "config.php";
include_once "connect.php";
?>
<?php
function affichepost(){
$post=mysql_query("select * from AP3_SP_user");
$post2=mysql_query("select id_type from AP3_SP_user where pseudo=\"".$_SESSION["user"]."\"") or die(mysql_error());
$p2=mysql_fetch_assoc($post2);
foreach($p2 as $res)
{	
}
$req_sujet="SELECT * FROM AP3_SP_post where id_post =".$_GET["id_post"]; //une ligne

$req_rep="SELECT * FROM AP3_SP_post where id_pere =".$_GET["id_post"];//lignes de réponses correspondantes au post

$sujet=mysql_query($req_sujet) or die(mysql_error());
$reponses=mysql_query($req_rep) or die(mysql_error());


					
		 $id_type=1;
		 $session=0;
		 if(isset($_SESSION["user"]))
		 {
echo "<div class='sujet'>";
			 $session=1; 
			while($row=mysql_fetch_assoc($sujet))
			{//affichage post
						echo "<div id='titre'>Titre: ".$row['titre']."</div>";
						echo "<div id='txt_post'>".$row['contenu']."</div>";
						echo "<div id='bas_post'> - Posté par ".$row['pseudo']." le ".$row['date']."</div><br/>";

					
						//bouton pour ajouter une nouvelle reponse
						echo "<form name='redirectreponse' action='formulairereponse.php?id_post=".$row["id_post"]."&id=".$_GET["id_categorie"]."&id_user=" .$_SESSION["user"] ."' method='post'>";?>
						<input type="submit" name="ajouterreponse" value="Repondre"/>
						</form> 
					<?php			
			}
echo "</div>";

			while($row2=mysql_fetch_assoc($reponses))
			{ //affichage des reponses
			echo "<div class='reponse'>";
				echo "<div id='titre'>Réponse: ".$row2['titre']."</div>";
				echo "<div id='txt_post'>".$row2['contenu']."</div>";
				echo "<div id='bas_post'> - Posté par ".$row2['pseudo']." le ".$row2['date']." - Rubrique : ".$row2['id_rubrique']."</div><br/>";
				
					if($res==3 || $row2["pseudo"]==$_SESSION["user"] )
					{

						echo "<a href='deletereponse.php?id_post=".$row2["id_post"]."&id_categorie=".$row2["id_rubrique"]."&id_pere=".$row2["id_pere"]."'>SupprimerReponse</a><br/>"; //lien supprime reponse
						echo "<br/><a href='modifierpost.php?id_post=".$row2["id_post"]."&id_categorie=".$row2["id_rubrique"]."&id_pere=".$row2["id_pere"]."'>modifierReponse</a><br/>"; //lien modifier reponse 
						echo "<br/>";		
					}
			echo "</div>";
			}
	}		
}